package com.xx.happychatboot.middleware.netty.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum WebSocketTypeEnum {
    LOGIN(1, "登录"),
    HEARTBEAT(2, "心跳包"),
    AUTHORIZE(3, "登录认证"),
    READ_ADD_FRIEND(10001,"已阅读好友申请信息"),
    ;

    private final Integer type;
    private final String desc;

    // 缓存
    private static Map<Integer, WebSocketTypeEnum> cache;

    static {
        cache = Arrays.stream(WebSocketTypeEnum.values()).collect(Collectors.toMap(WebSocketTypeEnum::getType, Function.identity()));
    }

    public static WebSocketTypeEnum of(Integer type) {
        return cache.get(type);
    }
}
